﻿namespace ExamV5.ManagSys
{
    using ExamV5;
    using System;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public class FrmSelectWork : Page
    {
        protected Button butAllDel;
        protected Button butAllSelect;
        protected Button butOneDel;
        protected Button butOneSelect;
        protected Button butQuery;
        protected HtmlForm frmuser;
        protected HtmlHead Head1;
        private HttpCookie httpCookie_0 = null;
        private HttpCookie httpCookie_1 = null;
        private HttpCookie httpCookie_2 = null;
        private HttpCookie httpCookie_3 = null;
        private int int_0 = 0;
        protected Label labSelectedTip;
        protected Label labSelectTip;
        protected ListBox LBSelect;
        protected ListBox LBSelected;
        private PublicFun publicFun_0 = new PublicFun();
        protected TextBox txtQuery;

        protected void butAllDel_Click(object sender, EventArgs e)
        {
            ListItem item = null;
            for (int i = 0; i < this.LBSelected.Items.Count; i++)
            {
                item = new ListItem(this.LBSelected.Items[i].Text, this.LBSelected.Items[i].Value);
                if (this.LBSelect.Items.IndexOf(item) == -1)
                {
                    this.LBSelect.Items.Add(item);
                }
            }
            this.LBSelected.Items.Clear();
            this.labSelectTip.Text = "待选职务<font color=red>(" + this.LBSelect.Items.Count + ")</font>";
            this.labSelectedTip.Text = "待选职务<font color=red>(" + this.LBSelected.Items.Count + ")</font>";
        }

        protected void butAllSelect_Click(object sender, EventArgs e)
        {
            ListItem item = null;
            for (int i = 0; i < this.LBSelect.Items.Count; i++)
            {
                item = new ListItem(this.LBSelect.Items[i].Text, this.LBSelect.Items[i].Value);
                if (this.LBSelected.Items.IndexOf(item) == -1)
                {
                    this.LBSelected.Items.Add(item);
                }
            }
            this.LBSelect.Items.Clear();
            this.labSelectTip.Text = "待选职务<font color=red>(" + this.LBSelect.Items.Count + ")</font>";
            this.labSelectedTip.Text = "待选职务<font color=red>(" + this.LBSelected.Items.Count + ")</font>";
        }

        protected void butOneDel_Click(object sender, EventArgs e)
        {
            string str = "";
            if (this.LBSelected.SelectedIndex > -1)
            {
                int num2 = 0;
                while (num2 < this.LBSelected.Items.Count)
                {
                    if (this.LBSelected.Items[num2].Selected)
                    {
                        if (this.LBSelect.Items.IndexOf(this.LBSelected.Items[num2]) == -1)
                        {
                            this.LBSelect.Items.Add(this.LBSelected.Items[num2]);
                        }
                        str = str + this.LBSelected.Items[num2].Value + "#";
                    }
                    num2++;
                }
                string[] strArray = str.Split(new char[] { '#' });
                if (strArray.Length > 1)
                {
                    for (int i = 0; i < strArray.Length; i++)
                    {
                        for (num2 = 0; num2 < this.LBSelected.Items.Count; num2++)
                        {
                            if (this.LBSelected.Items[num2].Value == strArray[i])
                            {
                                this.LBSelected.Items.Remove(this.LBSelected.Items[num2]);
                            }
                        }
                    }
                }
            }
            this.labSelectTip.Text = "待选职务<font color=red>(" + this.LBSelect.Items.Count + ")</font>";
            this.labSelectedTip.Text = "待选职务<font color=red>(" + this.LBSelected.Items.Count + ")</font>";
        }

        protected void butOneSelect_Click(object sender, EventArgs e)
        {
            string str = "";
            if (this.LBSelect.SelectedIndex > -1)
            {
                int num = 0;
                while (num < this.LBSelect.Items.Count)
                {
                    if (this.LBSelect.Items[num].Selected && (this.LBSelected.Items.IndexOf(this.LBSelect.Items[num]) == -1))
                    {
                        this.LBSelected.Items.Add(this.LBSelect.Items[num]);
                        str = str + this.LBSelect.Items[num].Value + "#";
                    }
                    num++;
                }
                string[] strArray = str.Split(new char[] { '#' });
                if (strArray.Length > 1)
                {
                    for (int i = 0; i < strArray.Length; i++)
                    {
                        for (num = 0; num < this.LBSelect.Items.Count; num++)
                        {
                            if (this.LBSelect.Items[num].Value == strArray[i])
                            {
                                this.LBSelect.Items.Remove(this.LBSelect.Items[num]);
                            }
                        }
                    }
                }
            }
            this.labSelectTip.Text = "待选职务<font color=red>(" + this.LBSelect.Items.Count + ")</font>";
            this.labSelectedTip.Text = "待选职务<font color=red>(" + this.LBSelected.Items.Count + ")</font>";
        }

        protected void butQuery_Click(object sender, EventArgs e)
        {
            this.method_0();
            this.labSelectTip.Text = "待选职务<font color=red>(" + this.LBSelect.Items.Count + ")</font>";
            this.labSelectedTip.Text = "待选职务<font color=red>(" + this.LBSelected.Items.Count + ")</font>";
        }

        private void method_0()
        {
            string strSql = "select ParmName,ParmValue from SysparmInfo where ParmMemo='Worker' and ParmName<>'' and ParmValue<>''";
            if (this.txtQuery.Text.Trim() != "")
            {
                strSql = strSql + " and ParmName like '%" + this.publicFun_0.CheckString(this.txtQuery.Text) + "%'";
            }
            this.LBSelect.Items.Clear();
            this.LBSelect.DataTextField = "ParmName";
            this.LBSelect.DataValueField = "ParmValue";
            this.LBSelect.DataSource = this.publicFun_0.RetrunDataView(strSql);
            this.LBSelect.DataBind();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.httpCookie_0 = new HttpCookie("ExamUserCode");
            this.httpCookie_0 = base.Request.Cookies["ExamUserCode"];
            this.httpCookie_1 = new HttpCookie("ExamUserName");
            this.httpCookie_1 = base.Request.Cookies["ExamUserName"];
            this.httpCookie_2 = new HttpCookie("ExamUserLevel");
            this.httpCookie_2 = base.Request.Cookies["ExamUserLevel"];
            this.httpCookie_3 = new HttpCookie("ExamDeptID");
            this.httpCookie_3 = base.Request.Cookies["ExamDeptID"];
            if ((this.httpCookie_0 != null) && (this.httpCookie_0.Value != ""))
            {
                base.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                base.Response.Cache.SetNoStore();
                this.httpCookie_0.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_0.Value));
                this.httpCookie_1.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_1.Value));
                this.httpCookie_2.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_2.Value));
                this.httpCookie_3.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_3.Value));
                if (base.Request["ID"] != null)
                {
                    this.int_0 = Convert.ToInt32(base.Request["ID"].ToString());
                }
                else
                {
                    this.int_0 = 0;
                }
                if (!base.IsPostBack)
                {
                    if (this.int_0 != 0)
                    {
                        ListItem item;
                        string str = "";
                        this.LBSelected.Items.Clear();
                        SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
                        connection.Open();
                        SqlCommand command = new SqlCommand("select LastWork from StudyPlanInfo where ID=" + this.int_0, connection);
                        SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
                        if (reader.Read())
                        {
                            str = reader["LastWork"].ToString();
                            item = new ListItem(reader["LastWork"].ToString(), reader["LastWork"].ToString());
                            this.LBSelected.Items.Add(item);
                        }
                        reader.Close();
                        command.Dispose();
                        connection.Close();
                        connection.Dispose();
                        string[] strArray = str.Split(new char[] { ',' });
                        this.LBSelected.Items.Clear();
                        for (int i = 0; i < strArray.Length; i++)
                        {
                            if (strArray[i].Trim().Trim() != "")
                            {
                                item = new ListItem(strArray[i].Trim(), strArray[i].Trim());
                                this.LBSelected.Items.Add(item);
                            }
                        }
                    }
                    this.method_0();
                    this.labSelectTip.Text = "待选职务<font color=red>(" + this.LBSelect.Items.Count + ")</font>";
                    this.labSelectedTip.Text = "待选职务<font color=red>(" + this.LBSelected.Items.Count + ")</font>";
                }
            }
            else
            {
                base.Response.Write("<script language=javascript>top.location.href='../Index.htm';self.close();</script>");
            }
        }
    }
}

